﻿using IsikFx.Project.CommonTypes.CRUD;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using IsikFx.Project.ClientApp.Helpers;

namespace IsikFx.Project.ClientApp.Content
{
    /// <summary>
    /// Interaction logic for AnnouncementEntry.xaml
    /// </summary>
    public partial class AnnouncementEntry : UserControl
    {
        public AnnouncementEntry()
        {
            InitializeComponent();
            InitPersonelTypeComboBox();
        }

        private void btnInsertAnnouncement_Click_1(object sender, RoutedEventArgs e)
        {
            if (CheckForm())
            {
                int roleType = 1;
                if (cbPersonelType.SelectedItem.ToString().Contains("Satış"))
                    roleType = 1;
                else if (cbPersonelType.SelectedItem.ToString().Contains("Retention"))
                    roleType = 2;
                CrudResponseMessage response = Helpers.Helper.InsertNewAnnouncement(txtTitle.Text, txtContent.Text, roleType);
                if (!response.HasError && response.Response.AffectedRows > 0)
                {
                    Helper.ShowMessage("Duyuru ekleme işleminiz başarıyla gerçekleşti.");
                }
                else if (response.HasError)
                {
                    Helper.ShowMessage(response.ErrorMessage);
                }
            }
            else
            {
                Helper.ShowMessage("Lütfen alanları doldurunuz.");
            }
        }

        private void InitPersonelTypeComboBox()
        {
            List<string> list = new List<string>();
            list.Add("Lütfen Seçiniz");
            list.Add("Satış Personeli");
            list.Add("Retention Personeli");

            cbPersonelType.ItemsSource = list;
        }

        private bool CheckForm()
        {
            bool _isValid = true;

            if (cbPersonelType.SelectedItem == null || cbPersonelType.SelectedIndex == 0)
            {
                _isValid = _isValid & false;
            }

            if (string.IsNullOrEmpty(txtTitle.Text))
            {
                _isValid = _isValid & false;
            }

            if (string.IsNullOrEmpty(txtContent.Text))
            {
                _isValid = _isValid & false;
            }

            return _isValid;
        }
    }
}
